﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Masuit.MyBlogs.EntityFrameworkCore.Migrations
{
    public partial class InitCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "advertisement",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(maxLength: 128, nullable: false),
                    ImageUrl = table.Column<string>(nullable: true),
                    ThumbImgUrl = table.Column<string>(nullable: true),
                    Description = table.Column<string>(maxLength: 1000, nullable: false),
                    Url = table.Column<string>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    UpdateTime = table.Column<DateTime>(nullable: false),
                    Weight = table.Column<int>(nullable: false),
                    Price = table.Column<decimal>(nullable: false),
                    Types = table.Column<string>(nullable: false),
                    ViewCount = table.Column<int>(nullable: false),
                    CategoryIds = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_advertisement", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "broadcast",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Email = table.Column<string>(nullable: true),
                    ValidateCode = table.Column<string>(nullable: true),
                    UpdateTime = table.Column<DateTime>(nullable: false),
                    SubscribeType = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_broadcast", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "category",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Name = table.Column<string>(maxLength: 64, nullable: false),
                    Description = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_category", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "donate",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    NickName = table.Column<string>(nullable: true),
                    Email = table.Column<string>(nullable: true),
                    QQorWechat = table.Column<string>(nullable: true),
                    EmailDisplay = table.Column<string>(nullable: true),
                    QQorWechatDisplay = table.Column<string>(nullable: true),
                    Amount = table.Column<string>(nullable: true),
                    Via = table.Column<string>(nullable: true),
                    DonateTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_donate", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "fastshare",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: true),
                    Link = table.Column<string>(nullable: true),
                    Sort = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_fastshare", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "internalmessage",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: true),
                    Content = table.Column<string>(nullable: true),
                    Link = table.Column<string>(nullable: true),
                    Time = table.Column<DateTime>(nullable: false),
                    Read = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_internalmessage", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "leavemessage",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    NickName = table.Column<string>(nullable: false),
                    Content = table.Column<string>(nullable: false),
                    PostDate = table.Column<DateTime>(nullable: false),
                    Email = table.Column<string>(nullable: true),
                    QQorWechat = table.Column<string>(nullable: true),
                    ParentId = table.Column<int>(nullable: false),
                    Browser = table.Column<string>(maxLength: 255, nullable: true),
                    OperatingSystem = table.Column<string>(maxLength: 255, nullable: true),
                    IsMaster = table.Column<bool>(nullable: false),
                    IP = table.Column<string>(nullable: true),
                    Location = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_leavemessage", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "links",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: false),
                    Url = table.Column<string>(nullable: false),
                    Except = table.Column<bool>(nullable: false),
                    Recommend = table.Column<bool>(nullable: false),
                    Weight = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_links", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "menu",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: false),
                    Icon = table.Column<string>(nullable: true),
                    Url = table.Column<string>(nullable: false),
                    Sort = table.Column<int>(nullable: false),
                    ParentId = table.Column<int>(nullable: false),
                    MenuType = table.Column<int>(nullable: false),
                    NewTab = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_menu", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "misc",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    Content = table.Column<string>(nullable: false),
                    PostDate = table.Column<DateTime>(nullable: false),
                    ModifyDate = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_misc", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "notice",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    Content = table.Column<string>(nullable: false),
                    PostDate = table.Column<DateTime>(nullable: false),
                    ModifyDate = table.Column<DateTime>(nullable: false),
                    ViewCount = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_notice", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "searchdetails",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Keywords = table.Column<string>(nullable: false),
                    SearchTime = table.Column<DateTime>(nullable: false),
                    IP = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_searchdetails", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "seminar",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    SubTitle = table.Column<string>(nullable: true),
                    Description = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_seminar", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "systemsetting",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: false),
                    Value = table.Column<string>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_systemsetting", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "userinfo",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Username = table.Column<string>(nullable: false),
                    NickName = table.Column<string>(nullable: false),
                    Password = table.Column<string>(nullable: false),
                    SaltKey = table.Column<string>(nullable: false),
                    IsAdmin = table.Column<bool>(nullable: false),
                    Email = table.Column<string>(nullable: true),
                    QQorWechat = table.Column<string>(nullable: true),
                    Avatar = table.Column<string>(nullable: true),
                    AccessToken = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_userinfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "post",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: false),
                    Author = table.Column<string>(maxLength: 24, nullable: false),
                    Content = table.Column<string>(nullable: false),
                    ProtectContent = table.Column<string>(nullable: true),
                    PostDate = table.Column<DateTime>(nullable: false),
                    ModifyDate = table.Column<DateTime>(nullable: false),
                    IsFixedTop = table.Column<bool>(nullable: false),
                    CategoryId = table.Column<int>(nullable: false),
                    Email = table.Column<string>(nullable: false),
                    Modifier = table.Column<string>(nullable: true),
                    ModifierEmail = table.Column<string>(nullable: true),
                    Label = table.Column<string>(maxLength: 256, nullable: true),
                    Keyword = table.Column<string>(maxLength: 256, nullable: true),
                    VoteUpCount = table.Column<int>(nullable: false),
                    VoteDownCount = table.Column<int>(nullable: false),
                    AverageViewCount = table.Column<double>(nullable: false),
                    TotalViewCount = table.Column<int>(nullable: false),
                    IP = table.Column<string>(nullable: true),
                    DisableComment = table.Column<bool>(nullable: false),
                    DisableCopy = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_post", x => x.Id);
                    table.ForeignKey(
                        name: "FK_post_category_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "category",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "loginrecord",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    IP = table.Column<string>(nullable: true),
                    LoginTime = table.Column<DateTime>(nullable: false),
                    Province = table.Column<string>(nullable: true),
                    PhysicAddress = table.Column<string>(nullable: true),
                    LoginType = table.Column<int>(nullable: false),
                    UserInfoId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_loginrecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_loginrecord_userinfo_UserInfoId",
                        column: x => x.UserInfoId,
                        principalTable: "userinfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "comment",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    NickName = table.Column<string>(maxLength: 24, nullable: false),
                    Email = table.Column<string>(nullable: true),
                    QQorWechat = table.Column<string>(nullable: true),
                    Content = table.Column<string>(nullable: false),
                    ParentId = table.Column<int>(nullable: false),
                    PostId = table.Column<int>(nullable: false),
                    CommentDate = table.Column<DateTime>(nullable: false),
                    Browser = table.Column<string>(maxLength: 255, nullable: true),
                    OperatingSystem = table.Column<string>(maxLength: 255, nullable: true),
                    IsMaster = table.Column<bool>(nullable: false),
                    VoteCount = table.Column<int>(nullable: false),
                    AgainstCount = table.Column<int>(nullable: false),
                    IP = table.Column<string>(nullable: true),
                    Location = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_comment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_comment_post_PostId",
                        column: x => x.PostId,
                        principalTable: "post",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "posthistoryversion",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    Title = table.Column<string>(maxLength: 128, nullable: false),
                    Content = table.Column<string>(nullable: false),
                    ProtectContent = table.Column<string>(nullable: true),
                    ViewCount = table.Column<int>(nullable: false),
                    ModifyDate = table.Column<DateTime>(nullable: false),
                    CategoryId = table.Column<int>(nullable: false),
                    PostId = table.Column<int>(nullable: false),
                    Email = table.Column<string>(maxLength: 255, nullable: true),
                    Modifier = table.Column<string>(nullable: true),
                    ModifierEmail = table.Column<string>(nullable: true),
                    Label = table.Column<string>(maxLength: 255, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_posthistoryversion", x => x.Id);
                    table.ForeignKey(
                        name: "FK_posthistoryversion_category_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "category",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_posthistoryversion_post_PostId",
                        column: x => x.PostId,
                        principalTable: "post",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "postmergerequest",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Status = table.Column<int>(nullable: false),
                    PostId = table.Column<int>(nullable: false),
                    Title = table.Column<string>(nullable: true),
                    Content = table.Column<string>(nullable: true),
                    Modifier = table.Column<string>(nullable: true),
                    ModifierEmail = table.Column<string>(nullable: true),
                    MergeState = table.Column<int>(nullable: false),
                    SubmitTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_postmergerequest", x => x.Id);
                    table.ForeignKey(
                        name: "FK_postmergerequest_post_PostId",
                        column: x => x.PostId,
                        principalTable: "post",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "seminarpost",
                columns: table => new
                {
                    Seminar_Id = table.Column<int>(nullable: false),
                    Post_Id = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_seminarpost", x => new { x.Seminar_Id, x.Post_Id });
                    table.ForeignKey(
                        name: "FK_seminarpost_post_Post_Id",
                        column: x => x.Post_Id,
                        principalTable: "post",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_seminarpost_seminar_Seminar_Id",
                        column: x => x.Seminar_Id,
                        principalTable: "seminar",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "seminarposthistoryversion",
                columns: table => new
                {
                    Seminar_Id = table.Column<int>(nullable: false),
                    PostHistoryVersion_Id = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_seminarposthistoryversion", x => new { x.Seminar_Id, x.PostHistoryVersion_Id });
                    table.ForeignKey(
                        name: "FK_seminarposthistoryversion_posthistoryversion_PostHistoryVers~",
                        column: x => x.PostHistoryVersion_Id,
                        principalTable: "posthistoryversion",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_seminarposthistoryversion_seminar_Seminar_Id",
                        column: x => x.Seminar_Id,
                        principalTable: "seminar",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_comment_PostId",
                table: "comment",
                column: "PostId");

            migrationBuilder.CreateIndex(
                name: "IX_loginrecord_UserInfoId",
                table: "loginrecord",
                column: "UserInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_post_CategoryId",
                table: "post",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_posthistoryversion_CategoryId",
                table: "posthistoryversion",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_posthistoryversion_PostId",
                table: "posthistoryversion",
                column: "PostId");

            migrationBuilder.CreateIndex(
                name: "IX_postmergerequest_PostId",
                table: "postmergerequest",
                column: "PostId");

            migrationBuilder.CreateIndex(
                name: "IX_seminarpost_Post_Id",
                table: "seminarpost",
                column: "Post_Id");

            migrationBuilder.CreateIndex(
                name: "IX_seminarposthistoryversion_PostHistoryVersion_Id",
                table: "seminarposthistoryversion",
                column: "PostHistoryVersion_Id");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "advertisement");

            migrationBuilder.DropTable(
                name: "broadcast");

            migrationBuilder.DropTable(
                name: "comment");

            migrationBuilder.DropTable(
                name: "donate");

            migrationBuilder.DropTable(
                name: "fastshare");

            migrationBuilder.DropTable(
                name: "internalmessage");

            migrationBuilder.DropTable(
                name: "leavemessage");

            migrationBuilder.DropTable(
                name: "links");

            migrationBuilder.DropTable(
                name: "loginrecord");

            migrationBuilder.DropTable(
                name: "menu");

            migrationBuilder.DropTable(
                name: "misc");

            migrationBuilder.DropTable(
                name: "notice");

            migrationBuilder.DropTable(
                name: "postmergerequest");

            migrationBuilder.DropTable(
                name: "searchdetails");

            migrationBuilder.DropTable(
                name: "seminarpost");

            migrationBuilder.DropTable(
                name: "seminarposthistoryversion");

            migrationBuilder.DropTable(
                name: "systemsetting");

            migrationBuilder.DropTable(
                name: "userinfo");

            migrationBuilder.DropTable(
                name: "posthistoryversion");

            migrationBuilder.DropTable(
                name: "seminar");

            migrationBuilder.DropTable(
                name: "post");

            migrationBuilder.DropTable(
                name: "category");
        }
    }
}
